home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-01-29 | 36.7 KB | 1,511 lines |
- Path: xanth!cs.odu.edu!Amiga-Request
- From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
- Newsgroups: comp.sources.amiga
- Subject: v90i033: env2manx 1.0 - ENV: that's compatible with Manx environment variables, Part01/01
- Message-ID: <11143@xanth.cs.odu.edu>
- Date: 29 Jan 90 00:07:54 GMT
- Sender: tadguy@cs.odu.edu
- Reply-To: ludde@nada.kth.se (Erik Lundevall)
- Lines: 1498
- Approved: tadguy@cs.odu.edu (Tad Guy)
- X-Mail-Submissions-To: Amiga@cs.odu.edu
-
- Submitted-by: ludde@nada.kth.se (Erik Lundevall)
- Posting-number: Volume 90, Issue 033
- Archive-name: devices/env2manx-1.0
-
- This program makes Commorore`s WB1.3 Env: environment variables
- compatible with MANX/Tomas Rokicki's.
-
- #!/bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: env-handler.c env-handler.h env.doc funcs.c funcs.h
- # globals.h makefile mountlist
- # Wrapped by tadguy@xanth on Sun Jan 28 19:07:43 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'env-handler.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'env-handler.c'\"
- else
- echo shar: Extracting \"'env-handler.c'\" \(5080 characters\)
- sed "s/^X//" >'env-handler.c' <<'END_OF_FILE'
- X/*
- X * FILE
- X * env-handler.c
- X *
- X * VERSION
- X * V1.0
- X *
- X * DESCRIPTION
- X * This program makes the env: environment variables compatible
- X * with the old MANX variables. (They said it couldn`t be done...)
- X *
- X * AUTHOR
- X * Anders `ALi' Lindgren
- X * Malarblick 8
- X * S-161 51 Bromma
- X * Sweden
- X *
- X * STATUS
- X * This program is in the Public Domain.
- X *
- X * CODE HISTORY
- X * 26-Sep-89 (07:50) Created the File.
- X * 26-Sep-89 (10:30) File basically completed. :-)
- X */
- X
- X#include "env-handler.h"
- X
- X
- X
- X/* Oh No, a global variable! */
- X
- Xstruct ArpBase * ArpBase;
- X
- X/*
- X * FUNCTION
- X * env_handler
- X *
- X * DESCRIPTION
- X * This function initializes all.
- X *
- X * NOTE
- X * Though this is the first function, I have not named it main().
- X * I can now see if there is any mistakes made at link time (ie. no
- X * startupcode shall be used.)
- X */
- X
- Xstatic void __saveds
- Xenv_handler( void )
- X{
- X register struct DosPacket * pkt; /* The actual packet */
- X register struct MsgPort * port; /* Process msg port */
- X struct Process * proc; /* My process */
- X struct Message * msg; /* Messages from port */
- X struct DosList * node; /* My devicenode */
- X char name[4]; /* Temporary name buffer */
- X int len;
- X char * ident; /* program identification */
- X
- X /*
- X * The following line simply embedds the text into the executable
- X * file, so the name of the project and the versionnumber
- X * can be seen.
- X */
- X
- X
- X ident = "\0*** ENV2MANX Env-Handler V1.0, 1990-01-20,"
- X "Written by Anders Lindgren ***";
- X
- X
- X proc = (struct Process *)FindTask(NULL);
- X
- X WaitPort( port = & proc->pr_MsgPort );
- X msg = GetMsg(port);
- X pkt = (struct DosPacket *) msg->mn_Node.ln_Name;
- X
- X
- X if ( ArpBase = (struct ArpBase *)OpenLibrary(ArpName, ArpVersion) ) {
- X
- X node = (struct DosList *) BTOC( pkt->dp_Arg3 );
- X
- X len = BtoCStr( & name[0] , node->dol_Name , 3);
- X if ( (Strncmp(name, "env", 3) == 0) && (len == 3) ) {
- X
- X /* Inform AD that we are here by complement the dosnode */
- X node->dol_Task = port;
- X
- X pkt->dp_Res1 = DOS_TRUE;
- X pkt->dp_Res2 = 0;
- X
- X ReplyPkt(pkt, port);
- X
- X main_lupe(port, node);
- X
- X node->dol_Task = NULL;
- X }
- X else {
- X /* Started under other name than env: */
- X pkt->dp_Res1 = DOS_FALSE;
- X pkt->dp_Res2 = ERROR_BAD_STREAM_NAME;
- X ReplyPkt(pkt, port);
- X }
- X CloseLibrary((struct Library *)ArpBase);
- X }
- X else { /* Arp did`t open */
- X pkt->dp_Res1 = DOS_FALSE;
- X pkt->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
- X ReplyPkt(pkt, port);
- X }
- X
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * main_lupe
- X *
- X * DESCRIPTION
- X * This is the `waitloop' of the handler. It get`s the massage,
- X * interpreted it, executes the right functions and exits.
- X */
- X
- Xstatic void
- Xmain_lupe(register struct MsgPort * port, register struct DosList * node)
- X{
- X register struct DosPacket * pkt;
- X register struct Message * msg;
- X BOOL quit;
- X
- X quit = FALSE;
- X
- X while (!quit) {
- X
- X WaitPort (port);
- X while (msg = GetMsg(port)) {
- X pkt = (struct DosPacket *)msg->mn_Node.ln_Name;
- X
- X pkt->dp_Res1 = DOS_FALSE;
- X pkt->dp_Res2 = 0;
- X
- X
- X switch(pkt->dp_Type) {
- X
- X /* Exit the handler. Note that no error checking
- X * is made. If you send this packet YOU must first
- X * be sure of that no program is using the handler.
- X * This packet was ONLY implemented for testing
- X * purpose!
- X */
- X case ACTION_DIE:
- X quit = TRUE;
- X break;
- X
- X case ACTION_FINDINPUT:
- X action_input(pkt, port);
- X break;
- X
- X case ACTION_FINDOUTPUT:
- X action_output(pkt, port);
- X break;
- X
- X case ACTION_END:
- X action_end(pkt);
- X break;
- X
- X case ACTION_READ:
- X action_read(pkt);
- X break;
- X
- X case ACTION_WRITE:
- X action_write(pkt);
- X break;
- X
- X case ACTION_LOCATE_OBJECT:
- X action_lock(pkt, port, node);
- X break;
- X
- X case ACTION_COPY_DIR:
- X action_copy_lock(pkt);
- X break;
- X
- X case ACTION_FREE_LOCK:
- X action_freelock(pkt);
- X break;
- X
- X case ACTION_DELETE_OBJECT:
- X action_delete(pkt);
- X break;
- X
- X case ACTION_EXAMINE_OBJECT:
- X action_examine_object(pkt);
- X break;
- X
- X case ACTION_EXAMINE_NEXT:
- X action_examine_next(pkt);
- X break;
- X
- X /* Fooling the client that we accept the following
- X * action types, so copy etc. won`t make a fuzz.
- X */
- X case ACTION_SET_PROTECT:
- X case ACTION_SET_COMMENT:
- X case ACTION_SET_DATE:
- X pkt->dp_Res1 = DOS_TRUE;
- X break;
- X
- X
- X default:
- X pkt->dp_Res1 = DOS_FALSE;
- X pkt->dp_Res2 = ERROR_ACTION_NOT_KNOWN;
- X break;
- X
- X } /* switch */
- X
- X ReplyPkt(pkt, port);
- X
- X } /* while */
- X } /* while */
- X
- X return;
- X
- X} /* main_lupe */
- X
- X
- X/*
- X * FUNCTION
- X * ReplyPkt
- X *
- X * DESCRIPTION
- X * Replies the Packet back to the client.
- X *
- X * NOTE
- X * This function is called even if Arp.Library didn`t open.
- X */
- X
- Xstatic void
- XReplyPkt(register struct DosPacket * pkt, register struct MsgPort * port)
- X{
- X register struct Message * msg;
- X register struct MsgPort * rport;
- X
- X rport = pkt->dp_Port;
- X msg = pkt->dp_Link;
- X pkt->dp_Port = port;
- X msg->mn_Node.ln_Name = (BYTE *)pkt;
- X msg->mn_Node.ln_Succ = NULL;
- X msg->mn_Node.ln_Pred = NULL;
- X
- X PutMsg(rport,msg);
- X return;
- X} /* ReplyPkt */
- END_OF_FILE
- if test 5080 -ne `wc -c <'env-handler.c'`; then
- echo shar: \"'env-handler.c'\" unpacked with wrong size!
- fi
- # end of 'env-handler.c'
- fi
- if test -f 'env-handler.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'env-handler.h'\"
- else
- echo shar: Extracting \"'env-handler.h'\" \(832 characters\)
- sed "s/^X//" >'env-handler.h' <<'END_OF_FILE'
- X/*
- X * FILE
- X * env-handler.h
- X *
- X * DESCRIPTION
- X * This file is the headerfile for the env-handler.c file.
- X */
- X
- X /* Headerfiles */
- X#include <exec/types.h>
- X#include <exec/nodes.h>
- X#include <exec/ports.h>
- X#include <exec/memory.h>
- X#include <libraries/dos.h>
- X#include <libraries/dosextens.h>
- X
- X#define ARP_PRIVATE
- X#include <libraries/arpbase.h>
- X
- X#include <proto/exec.h>
- X
- X#include "globals.h"
- X
- X
- X /* Definitions */
- X#define BTOC(x) ((void *) ( ((LONG)(x)) << 2 ) )
- X#define CTOB(x) ((BPTR) ( ((LONG)(x)) >> 2 ) )
- X
- X#define DOS_FALSE (0)
- X#define DOS_TRUE (-1)
- X
- X
- X /* Forward references */
- Xextern void __saveds env_handler (void);
- Xextern void main_lupe (register struct MsgPort *,
- X register struct DosList *);
- Xextern void ReplyPkt (register struct DosPacket *,
- X register struct MsgPort *);
- END_OF_FILE
- if test 832 -ne `wc -c <'env-handler.h'`; then
- echo shar: \"'env-handler.h'\" unpacked with wrong size!
- fi
- # end of 'env-handler.h'
- fi
- if test -f 'env.doc' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'env.doc'\"
- else
- echo shar: Extracting \"'env.doc'\" \(4376 characters\)
- sed "s/^X//" >'env.doc' <<'END_OF_FILE'
- X
- X ***** ** * * * ##### ** ** ** ** * * *
- X * * * * * * # # * * * * * * * * * * *
- X *** * * * * * ## * ** * ****** * * * **
- X * * * * * * ## * * * * * * * * *
- X ***** * ** * ####### * * * * * ** * *
- X
- X
- X -------------------------------------------------------------------
- X
- X Written by:
- X Anders `ALi' Lindgren
- X
- X This program makes Commorore`s WB1.3 Env:
- X environment variables compatible with
- X MANX/Tomas Rokickis.
- X
- X -------------------------------------------------------------------
- X
- X
- X When Commore released WB1.3 they included someting many people were
- X waiting for, a official environment variable standard. But there
- X was one big problem, before WB1.3 there existed already one `de
- X facto' standard. This was constructed by MANX and Tomas Rokicki.
- X ENV: and the MANX variables has been, up to now, totally
- X incompatible.
- X
- X This ENV: handler is a program which uses the MANX variables as
- X storage area for the ENV: variables. Resulting in total
- X compability. You can now write a variable to ENV:, and then read it
- X by a MANX compatible function, and vice versa.
- X
- X As far as I know the ENV: handler works just like the old ENV:,
- X excpet a few small details:
- X - Subdirectories, Protection bits and FileNotes is NOT
- X supported.
- X - The String terminator (character value 0) is considerd
- X end of string. Everything behind it will be stripped off.
- X
- X
- X Note, that the handler is constructed for short strings. Don`t use
- X it for normal temporary storage! ~~~~~~~~
- X
- X
- XUSAGE To use the env-handler, put it in your L: directory (probably the
- X L directory on your bootdisk.) Merge the file `mountlist' together
- X with DEVS:mountlist. Then type `mount ENV:' at the CLI (or Shell)
- X prompt. If you are permanently going to use the handler then insert
- X the line `mount env:' in your s:Startup-Sequence file.
- X (Env-handler demands to have arp.library in your LIBS: directory.
- X If you don`t have it, you can probably get if from the same source
- X as this program. My appologies to anybody not using the
- X arp.library,)
- X
- X
- XCOMPILATION
- X The sourcefiles needed to generate the program is env-handler.c,
- X env-handler.h, funcs.c, funcs.h and globals.h. These files are
- X relatively well commented, so anybody familar with device-handlers
- X shall be able to follow my thougths.
- X To compile the programs use Lattice C V5 (or newer). All
- X compilation rules is in the file `makefile'. Note that I have
- X tried to keep both compilation time and program size down. For
- X example I don`t link with neither lc.lib nor amiga.lib.
- X
- X
- XREFERENCES
- X Books and article references:
- X
- X - `The AmigaDOS Manual', 2nd editon. Bantam Books, Commodore-Amiga.
- X - `Device Handlers: How to create an AmigaDOS device driver'.
- X Steve Simpson, UK-Transactor/Amiga. Vol 1, issue 6, p60.
- X (Watch the bugs in Table 1, Arg1 is supposed to be fh->fh_Arg1
- X in ACTION_READ, _WRITE, _CLOSE and _SEEK)
- X - `The Kickstart guide to the Amiga', Ariadne Software Ltd.
- X - `The Packet interface to AmigaDOS, in C' Mattew Dillon.
- X UK-Transactor/Amiga. Vol 1, issue 1, p15.
- X - Several PD/SW device handlers (including PathAss.)
- X
- X
- XAUTHOR The ENV: handler was written by:
- X Anders `ALi' Lindgren
- X Malarblick 8
- X S-161 51 Bromma
- X Sweden.
- X
- X Phone: No thanks! No calls at 3 AM.
- X
- X I can be reached on the Swedish Amiga databases:
- X Camelot - 08 - 34 85 23.
- X NT - 08 - 52 11 45.
- X ARTLine - 0755 - 61 537
- X
- XSTATUS The handler, the sourcecode and documentation is placed in the
- X Public Domain and may be used by any private person. The only
- X rule is that you MUST send me a postcard if you`re using it.
- X This program may be included in any commersial products if my
- X WRITTEN permission is granted, and a registred copy of the
- X product is sent to me.
- X Use the product ON YOUR OWN RISK!
- X
- X Use also my other programs:
- X - PathAssign. A general path device, assign several
- X directories to one logical device. (ShareWare)
- X - Pwd/Pop. A turbocharged CD command. Stores the old
- X directories on a stack, which can be popped back. (PD)
- X - SetLace. Handles the interlace mode on the workbench
- X screem. (freely distributable)
- X - Colour, a utility to switch between fixed named
- X coloursetups on the workbench screen. (Soon released)
- END_OF_FILE
- if test 4376 -ne `wc -c <'env.doc'`; then
- echo shar: \"'env.doc'\" unpacked with wrong size!
- fi
- # end of 'env.doc'
- fi
- if test -f 'funcs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'funcs.c'\"
- else
- echo shar: Extracting \"'funcs.c'\" \(16462 characters\)
- sed "s/^X//" >'funcs.c' <<'END_OF_FILE'
- X/*
- X * FILE
- X * funcs.c
- X *
- X * DESCRIPTION
- X * All the functions for actually read and write the MANX
- X * environment variables.
- X *
- X * AUHOR
- X * Anders `ALi' Lindgren
- X * Marlarblick 8
- X * S-161 51 Bromma
- X * Sweden
- X *
- X * STATUS
- X * This file is in the Public Domain.
- X *
- X * CODE HISTORY
- X * 26-Sep-89 (10:51) Created this file.
- X * 27-Sep-89 (18:56) Read works ok.
- X * (19:27) ReAlloc written.
- X * (12:00) Both Read and Write works ok.
- X * 28-Sep-89 (14:00) Locks implemented.
- X *
- X * 1-Oct-89 No hacking. I was employed by Commodore,
- X * ... Sweden at the Alvsjo copmuter fair.
- X * 6-Oct-89
- X * 6-Oct-89 (Gee, today I bougth a 2000 :-) )
- X *
- X * 6-Oct-89 (23:30) Implemented Directory functions. Some
- X * people wanted it badly.
- X * 8-Oct-89 (12:00) Directory functions works ok.
- X *
- X * ... (I got my hands on MicroGNUEmacs 3. It`s GREAT!)
- X *
- X * 17-Oct-89 I threw out the old directory functions, becauce
- X * they didn`t function the way I liked.
- X *
- X * 20-Jan-90 I`m sorry, but I have been up to my neck into
- X * other things so I haven`t been able to work
- X * on the project. Well, now it`s released, enjoy!
- X *
- X * DISCUSSION
- X * Change __builtin_memcpy to CopyMem???
- X */
- X
- X#include "funcs.h"
- X
- X/*
- X * FUNCTION
- X * action_input
- X *
- X * DESCRIPTION
- X * Read an MANX variable. This function copies the variable
- X * value to a temporary buffer.
- X *
- X * The valuebuf structure conatisn the following fields:
- X * vb_buf - Pointer to the temporary buffer.
- X * vb_pos - Index, pointing to the next char to be read.
- X * vb_end - Size of the Buffer.
- X *
- X * When vb_pos and vb_end is equal, all data was been read.
- X */
- X
- Xvoid
- Xaction_input (register struct DosPacket * pkt, struct MsgPort * port)
- X{
- X register struct FileHandle * fh;
- X register struct valuebuf * vb;
- X register char * var;
- X register int len;
- X char name[NAMESIZE];
- X char * varname;
- X
- X pkt->dp_Res1 = DOS_FALSE;
- X
- X fh = (struct FileHandle *)BTOC(pkt->dp_Arg1);
- X
- X BtoCStr(name, pkt->dp_Arg3, NAMESIZE-1);
- X varname = BaseName ( name );
- X
- X if ( * varname ) {
- X
- X Forbid();
- X
- X if (var = mygetenv(varname)) {
- X
- X if (vb = (struct valuebuf *) AllocMem( sizeof(struct valuebuf),
- X MEMF_PUBLIC | MEMF_CLEAR ) ) {
- X
- X fh->fh_Type = port;
- X fh->fh_Arg1 = (long) vb;
- X
- X len = __builtin_strlen(var);
- X
- X if (vb->vb_buf = AllocMem(len, MEMF_PUBLIC | MEMF_CLEAR)) {
- X vb->vb_end = len;
- X vb->vb_pos = 0;
- X
- X __builtin_memcpy(vb->vb_buf, var, len);
- X
- X vb->vb_flags = ENVF_READ;
- X
- X pkt->dp_Res1 = DOS_TRUE;
- X }
- X else {
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X FreeMem((char *)vb, sizeof(struct valuebuf));
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
- X }
- X
- X Permit();
- X }
- X else {
- X pkt->dp_Res2 = ERROR_BAD_STREAM_NAME;
- X }
- X
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_read
- X *
- X * DESCRIPTION
- X * Writes the buffer to the fh.
- X */
- X
- Xvoid
- Xaction_read (register struct DosPacket * pkt)
- X{
- X register struct valuebuf * vb;
- X register int num;
- X
- X vb = (struct valuebuf *)pkt->dp_Arg1;
- X
- X if (vb->vb_flags & ENVF_READ) {
- X
- X /* Already read all? */
- X if (vb->vb_pos == vb->vb_end) {
- X pkt->dp_Res1 = 0;
- X }
- X else {
- X /* Get the smallest, buffer or remaining chars */
- X if ( (vb->vb_end - vb->vb_pos) <= pkt->dp_Arg3 ) {
- X num = vb->vb_end - vb->vb_pos;
- X }
- X else {
- X num = pkt->dp_Arg3;
- X }
- X
- X __builtin_memcpy( (void *)pkt->dp_Arg2,
- X (void *)(vb->vb_buf + vb->vb_pos), num );
- X
- X vb->vb_pos += num;
- X
- X pkt->dp_Res1 = num;
- X }
- X }
- X else {
- X pkt->dp_Res1 = 0;
- X pkt->dp_Res2 = ERROR_OBJECT_WRONG_TYPE;
- X }
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_output
- X *
- X * DESCRIPTION
- X * Open the env: for writing a variable.
- X * This function allocates memory for the namestring.
- X * It doesn`t allocate memory for the buffer, because if the
- X * vb_buf is zero (ie. no write has been made) the Setenv
- X * function removes the variable.
- X */
- X
- Xvoid
- Xaction_output (register struct DosPacket * pkt, struct MsgPort * port)
- X{
- X register struct valuebuf * vb;
- X register char * varname;
- X register int namelen;
- X struct FileHandle * fh;
- X char name[NAMESIZE];
- X
- X pkt->dp_Res1 = DOS_FALSE;
- X
- X if (vb = (struct valuebuf *) AllocMem( sizeof(struct valuebuf),
- X MEMF_PUBLIC | MEMF_CLEAR ) ) {
- X
- X fh = (struct FileHandle *)BTOC(pkt->dp_Arg1);
- X
- X BtoCStr(name, pkt->dp_Arg3, NAMESIZE-1);
- X varname = BaseName( name );
- X
- X if ( * varname ) {
- X namelen = __builtin_strlen(varname) + 1;
- X
- X if (vb->vb_name = DosAllocMem(namelen)) {
- X __builtin_memcpy(vb->vb_name, varname, namelen);
- X
- X fh->fh_Type = port;
- X fh->fh_Arg1 = (long) vb;
- X
- X vb->vb_flags = ENVF_WRITE;
- X
- X pkt->dp_Res1 = DOS_TRUE;
- X return; /* Correct exit */
- X }
- X /* Error hancdling code */
- X else {
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_BAD_STREAM_NAME;
- X }
- X FreeMem((char *)vb, sizeof(struct valuebuf));
- X }
- X else {
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X }
- X return; /* Error Exit! */
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_write
- X *
- X * DESCRIPTON
- X * Called when a client writes the contents of a environment
- X * variable.
- X * The data is stored at at buffer. If the buffer is smaler
- X * than the data, the buffer is expanded.
- X * BUFSIZE is the amount of extra memory which shall be
- X * allocated at a ReAlloc call.
- X * (If BUFSIZE is zero, a ReAlloc call will be made at
- X * every write.)
- X *
- X * NOTE
- X * No errorchecking is made on the ReAlloc function, yet....
- X */
- X
- Xvoid
- Xaction_write (register struct DosPacket * pkt)
- X{
- X register struct valuebuf * vb;
- X register char * newbuf;
- X
- X vb = (struct valuebuf *)pkt->dp_Arg1;
- X
- X if (vb->vb_flags & ENVF_WRITE) {
- X
- X if (vb->vb_pos + pkt->dp_Arg3 + 1 >= vb->vb_end) {
- X newbuf = ReAlloc(vb->vb_buf, vb->vb_end,
- X vb->vb_end + pkt->dp_Arg3 + BUFSTEP, MEMF_CLEAR);
- X if (newbuf == NULL) {
- X FreeMem (vb->vb_buf, vb->vb_end);
- X DosFreeMem (vb->vb_name);
- X FreeMem ((char *)vb, sizeof(struct valuebuf));
- X pkt->dp_Res1 = 0;
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X return;
- X }
- X vb->vb_buf = newbuf;
- X vb->vb_end += pkt->dp_Arg3 + BUFSTEP;
- X }
- X __builtin_memcpy(vb->vb_buf + vb->vb_pos, (void *)pkt->dp_Arg2,
- X pkt->dp_Arg3);
- X vb->vb_pos += pkt->dp_Arg3;
- X
- X pkt->dp_Res1 = pkt->dp_Arg3;
- X }
- X else {
- X pkt->dp_Res1 = 0;
- X pkt->dp_Res2 = ERROR_OBJECT_WRONG_TYPE;
- X }
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_end
- X *
- X * DESCRIPTION
- X * This function is executed when someone Close()`s the filehandler.
- X *
- X * On read, it simply frees the memory. On Write, the actual
- X * writing takes place here.
- X */
- X
- Xvoid
- Xaction_end (register struct DosPacket * pkt)
- X{
- X register struct valuebuf * vb;
- X
- X pkt->dp_Res1 = DOS_FALSE;
- X
- X if (vb = (struct valuebuf *)pkt->dp_Arg1) {
- X
- X if (vb->vb_flags & ENVF_READ) {
- X if (vb->vb_buf && vb->vb_end) {
- X FreeMem( (char *)vb->vb_buf, vb->vb_end);
- X FreeMem( (char *)vb, sizeof(struct valuebuf) );
- X }
- X pkt->dp_Res1 = DOS_TRUE;
- X }
- X else if (vb->vb_flags & ENVF_WRITE) {
- X if (vb->vb_name) {
- X Setenv(vb->vb_name, vb->vb_buf);
- X DosFreeMem(vb->vb_name);
- X }
- X if (vb->vb_buf) {
- X FreeMem(vb->vb_buf, vb->vb_end);
- X }
- X FreeMem((char *)vb, sizeof(struct valuebuf));
- X
- X pkt->dp_Res1 = DOS_TRUE;
- X }
- X else { /* Error */
- X pkt->dp_Res2 = ERROR_OBJECT_WRONG_TYPE;
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_OBJECT_WRONG_TYPE;
- X }
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_lock
- X *
- X * DESCRIPTION
- X * Lock the env: device, or a `file'. If a file is locked, the filename
- X * is copied to a aread pointed to by lock->fl_Name.
- X *
- X * ARGUMENTS
- X * Arg1 : Lock
- X * Arg2 : Name
- X * Arg3 : Mode
- X */
- X
- Xvoid
- Xaction_lock (register struct DosPacket * pkt,
- X struct MsgPort * port,
- X struct DosList * node)
- X{
- X register struct myFileLock * lock;
- X char name[NAMESIZE];
- X char * namebase;
- X
- X pkt->dp_Res1 = NULL;
- X
- X if (lock = (struct myFileLock *)AllocMem(sizeof(struct myFileLock),
- X MEMF_PUBLIC | MEMF_CLEAR)) {
- X pkt->dp_Res1 = CTOB(lock);
- X
- X lock->fl_Access = pkt->dp_Arg3;
- X lock->fl_Task = port;
- X lock->fl_Volume = CTOB(node);
- X
- X BtoCStr(name, pkt->dp_Arg2, NAMESIZE-1);
- X if (* (namebase = BaseName( name ))) {
- X if ( (lock->fl_Name = getenvname( namebase )) == NULL ) {
- X FreeMem ((char *)lock, sizeof(struct myFileLock));
- X pkt->dp_Res1 = NULL;
- X pkt->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
- X }
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X }
- X
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_copy_lock
- X *
- X * DESCRIPTION
- X * Implement the DupLock function.
- X */
- X
- Xvoid
- Xaction_copy_lock (register struct DosPacket * pkt)
- X{
- X register struct myFileLock * newlock;
- X register struct myFileLock * oldlock;
- X register int namelen;
- X
- X pkt->dp_Res1 = NULL;
- X
- X if (oldlock = (struct nyFileLock *)BTOC(pkt->dp_Arg1)) {
- X
- X if (newlock = (struct myFileLock *)AllocMem(sizeof(struct myFileLock),
- X MEMF_PUBLIC | MEMF_CLEAR)) {
- X pkt->dp_Res1 = CTOB(newlock);
- X
- X newlock->fl_Access = oldlock->fl_Access;
- X newlock->fl_Task = oldlock->fl_Task;
- X newlock->fl_Volume = oldlock->fl_Volume;
- X
- X if (oldlock->fl_Name) {
- X namelen = __builtin_strlen(oldlock->fl_Name);
- X if (newlock->fl_Name = DosAllocMem( namelen + 1 )) {
- X __builtin_memcpy (newlock->fl_Name, oldlock->fl_Name, namelen );
- X }
- X else {
- X pkt->dp_Res1 = NULL;
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X FreeMem ((char *) newlock, sizeof(struct myFileLock));
- X }
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_NO_FREE_STORE;
- X }
- X }
- X
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_freelock
- X *
- X * DESCRIPTION
- X * Frees the lock.
- X */
- X
- Xvoid
- Xaction_freelock(register struct DosPacket * pkt)
- X{
- X register struct myFileLock * lock;
- X
- X if (lock = BTOC(pkt->dp_Arg1)) {
- X if (lock->fl_Name) {
- X DosFreeMem((char *) lock->fl_Name);
- X }
- X FreeMem((char *)lock, sizeof(struct myFileLock));
- X }
- X pkt->dp_Res1 = DOS_TRUE;
- X
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_delete
- X *
- X * DESCRIPTION
- X * Delete a MANX variable.
- X */
- X
- Xvoid
- Xaction_delete(register struct DosPacket * pkt)
- X{
- X char name[NAMESIZE];
- X char * varname;
- X
- X BtoCStr(name, pkt->dp_Arg2, NAMESIZE-1);
- X varname = BaseName( name );
- X
- X if (* varname) {
- X if (Setenv(varname, NULL)) {
- X pkt->dp_Res1 = DOS_TRUE;
- X }
- X else {
- X /* As close at is can be. */
- X pkt->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_BAD_STREAM_NAME;
- X }
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_examine_object
- X *
- X * DESCRIPTION
- X * This function returns information about either ENV: itself
- X * os a single varable. It fills in the FileInfoBlock with
- X * appropriate values.
- X */
- X
- Xvoid
- Xaction_examine_object(register struct DosPacket * pkt)
- X{
- X register struct myFileLock * lock;
- X register struct FileInfoBlock * fib;
- X
- X if (lock = (struct myFileLock *) BTOC(pkt->dp_Arg1)) {
- X if (fib = (struct FileInfoBlock *)BTOC(pkt->dp_Arg2)) {
- X
- X if (lock->fl_Name == NULL) {
- X
- X fib->fib_DiskKey = FIRST_KEY;
- X fib->fib_DirEntryType = 2; /* Directory */
- X fib->fib_EntryType = 2;
- X fib->fib_Size = 0;
- X fib->fib_NumBlocks = 0;
- X
- X CtoBStr( "ENV", CTOB(fib->fib_FileName), 4);
- X }
- X else {
- X fib->fib_DiskKey = FIRST_KEY;
- X fib->fib_DirEntryType = -3;
- X fib->fib_EntryType = -3;
- X Forbid();
- X fib->fib_Size =
- X __builtin_strlen(mygetenv(lock->fl_Name));
- X Permit();
- X fib->fib_NumBlocks = 1;
- X
- X CtoBStr ( lock->fl_Name, CTOB(fib->fib_FileName), 30);
- X }
- X
- X fib->fib_Protection = 0x00; /* ----rwed */
- X fib->fib_Comment[0] = 0;
- X /* DateStamp( (long *) & fib->fib_Date ); /* Edit later! */
- X
- X pkt->dp_Res1 = DOS_TRUE;
- X
- X }
- X else { /* No fib */
- X pkt->dp_Res2 = ERROR_OBJECT_WRONG_TYPE;
- X }
- X }
- X else { /* No lock */
- X pkt->dp_Res2 = ERROR_INVALID_LOCK;
- X }
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * action_examine_next
- X *
- X * DESCTIPTION
- X * This function:
- X * - handles the `examine next' packet.
- X * - is called as part of `examine object' funcetion.
- X *
- X * It fills in the `FileInfoBlock' with appropriate values.
- X */
- X
- Xvoid
- Xaction_examine_next (register struct DosPacket * pkt)
- X{
- X register struct myFileLock * lock;
- X register struct FileInfoBlock * fib;
- X register char * newname;
- X register LONG namelen;
- X
- X if (lock = (struct myFileLock *) BTOC(pkt->dp_Arg1)) {
- X if (fib = (struct FileInfoBlock *)BTOC(pkt->dp_Arg2)) {
- X
- X Forbid();
- X
- X if (newname = getnextenv(fib, pkt) ) {
- X for (namelen = 0; newname[namelen] != '='; namelen++)
- X ;
- X
- X fib->fib_DiskKey += 1;
- X fib->fib_DirEntryType = -3;
- X fib->fib_Protection = 0x00; /* ----rwed */
- X fib->fib_EntryType = -3;
- X fib->fib_Size =
- X __builtin_strlen(newname) - namelen - 1;
- X fib->fib_NumBlocks = 1;
- X /* DateStamp( (long *) & fib->fib_Date ); /* Edit later! */
- X fib->fib_Comment[0] = 0;
- X
- X __builtin_memcpy( fib->fib_FileName + 1, newname, namelen);
- X fib->fib_FileName[0] = namelen;
- X
- X pkt->dp_Res1 = DOS_TRUE;
- X }
- X Permit();
- X }
- X else {
- X pkt->dp_Res2 = ERROR_OBJECT_WRONG_TYPE;
- X }
- X }
- X else {
- X pkt->dp_Res2 = ERROR_INVALID_LOCK;
- X }
- X return;
- X}
- X
- X
- X/*
- X * FUNCTION
- X * mygetenv
- X *
- X * DESCRIPTION
- X * Get a MANX environment variable.
- X * I can`t use the Arp function `getenv', because it will call
- X * ENV: if the variable doesn`t exist in the MANX area, resulting
- X * in a loop loop loop loop loop.....
- X *
- X * The EnvSpace is builtup by strings in the form:
- X * name=value
- X * They are separated by one \0 and they are ended by two.
- X *
- X * NOTE
- X * The task MUST be Forbid()`ed before this function is called!
- X */
- X
- Xstatic char *
- Xmygetenv(register char * name)
- X{
- X register char * p;
- X register int len;
- X
- X if ( p = ((struct EnvBase*)ArpBase->EnvBase)->EnvSpace ) {
- X
- X len = __builtin_strlen(name);
- X
- X while (*p) {
- X if (Strncmp(p, name, len) == 0) {
- X if ( p[len] == '=' ) {
- X return (& p[len+1]);
- X }
- X }
- X p += __builtin_strlen(p) + 1;
- X }
- X }
- X return(NULL);
- X}
- X
- X
- X/*
- X * FUNCTION
- X * getnextenv
- X *
- X * DESCRIPTION
- X * Get the next environment variable. If an error accured the correct
- X * errorcode is placed in pkt->dp_Res2 and a NULL is returned.
- X *
- X * NOTE
- X * This function MUST be called in Forbid()`ed state.
- X */
- X
- Xstatic char *
- Xgetnextenv (register struct FileInfoBlock * fib, register struct DosPacket * pkt)
- X{
- X register char * p;
- X register int len;
- X
- X if ( p = ((struct EnvBase*)ArpBase->EnvBase)->EnvSpace ) {
- X
- X if (fib->fib_DirEntryType > 0) {
- X if (*p) {
- X return (p);
- X }
- X else {
- X pkt->dp_Res2 = ERROR_NO_MORE_ENTRIES;
- X return (NULL);
- X }
- X }
- X
- X while (*p) {
- X len = __builtin_strlen(p);
- X
- X if ( (Strncmp(p, fib->fib_FileName + 1,
- X * fib->fib_FileName) == 0)
- X && (p[* fib->fib_FileName] == '=') ) {
- X
- X if ( * (p + len + 1) ) {
- X return (p + len + 1);
- X }
- X else {
- X pkt->dp_Res2 = ERROR_NO_MORE_ENTRIES;
- X return (NULL);
- X }
- X }
- X p += len + 1;
- X }
- X pkt->dp_Res2 = ERROR_OBJECT_NOT_FOUND; /* Correct??? */
- X }
- X return (NULL); /* No environment at all, or entry not found */
- X}
- X
- X
- X/*
- X * FUNCTION
- X * getenvname
- X *
- X * DESCRIPTION
- X * Get the name of an environment variable.
- X *
- X * NOTE
- X * This function MUST be called in Forbid()`ed state!
- X */
- X
- Xstatic char *
- Xgetenvname( register char * orgname )
- X{
- X register char * p;
- X register int len;
- X register char * newname;
- X register int namelen;
- X
- X if ( p = ((struct EnvBase*)ArpBase->EnvBase)->EnvSpace ) {
- X
- X namelen = __builtin_strlen( orgname );
- X
- X while (*p) {
- X len = __builtin_strlen(p);
- X
- X if ( (Strncmp(p, orgname, namelen) == 0) &&
- X (p[namelen] == '=') ) {
- X newname = DosAllocMem (namelen+1);
- X __builtin_memcpy( newname, p, namelen );
- X return ( newname );
- X }
- X p += len + 1;
- X }
- X }
- X return (NULL);
- X}
- X
- X
- X/*
- X * FUNCTION
- X * ReAlloc
- X *
- X * DESCRIPTION
- X * Alloctes a biger memory area and copies the contens of
- X * the original block. It then releases the original
- X * block.
- X *
- X * RETURNS
- X * A pointer to the new memory block. Or a NULL is
- X * AllocMem failed, in which case the original
- X * memory block is NOT released.
- X */
- X
- Xstatic void *
- XReAlloc ( void * oldbuf, long oldsize, long newsize, long flags )
- X{
- X void * newbuf;
- X
- X if (newbuf = AllocMem(newsize, flags)) {
- X
- X if ((oldbuf != NULL) && (oldsize != 0L)) {
- X __builtin_memcpy( newbuf, oldbuf, MAX(oldsize, newsize) );
- X FreeMem( oldbuf, oldsize );
- X }
- X }
- X return (newbuf);
- X}
- END_OF_FILE
- if test 16462 -ne `wc -c <'funcs.c'`; then
- echo shar: \"'funcs.c'\" unpacked with wrong size!
- fi
- # end of 'funcs.c'
- fi
- if test -f 'funcs.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'funcs.h'\"
- else
- echo shar: Extracting \"'funcs.h'\" \(2266 characters\)
- sed "s/^X//" >'funcs.h' <<'END_OF_FILE'
- X/*
- X * FILE
- X * funcs.h
- X *
- X * DESCRIPTION
- X * This file is the headerfile for the funcs.c file.
- X * It contains includes, structure definitions, definitions
- X * and forward references.
- X */
- X
- X /* Headerfiles */
- X#include <exec/types.h>
- X#include <exec/nodes.h>
- X#include <exec/ports.h>
- X#include <exec/memory.h>
- X#include <libraries/dos.h>
- X#include <libraries/dosextens.h>
- X
- X#include <string.h>
- X
- X#define ARP_PRIVATE
- X#include <libraries/arpbase.h>
- X
- X#include <proto/exec.h>
- X
- X#include "globals.h" /* All global definitions */
- X
- X/*
- X * STRUCTURE
- X * valuebuf
- X *
- X * DESCRIPTION
- X * Store the value of the variable temporary.
- X *
- X * When this strucure is used for reading, the vb_buf points
- X * to an internal buffer containing the value. The vb_pos
- X * is the read pointer and the vb_end is size of the buffer.
- X *
- X * During writing, the vb_buf points to a writing buffer,
- X * vb_pos is the write pointer, and vb_end is the size of
- X * the write. If the buffer is to small ReAlloc is called.
- X * The filename is stored in vb_name.
- X */
- X
- Xstruct valuebuf {
- X char * vb_buf;
- X long vb_end;
- X long vb_pos;
- X long vb_flags;
- X char * vb_name;
- X};
- X
- X
- X/*
- X * STRUCTURE
- X * myFileLock
- X *
- X * DESCRIPTION
- X * This is a standard `FileLock' structure, but with the fl_Key
- X * field changed to fl_Name.
- X */
- X
- Xstruct myFileLock {
- X BPTR fl_Link;
- X char * fl_Name; /* Used to be `LONG fl_Key' */
- X LONG fl_Access;
- X struct MsgPort * fl_Task;
- X BPTR fl_Volume;
- X};
- X
- X
- X/*
- X * DEFINTIONS
- X */
- X
- X#define BTOC(x) ((void *) ( ((LONG)(x)) << 2 ) )
- X#define CTOB(x) ((BPTR) ( ((LONG)(x)) >> 2 ) )
- X
- X#define DOS_FALSE (0)
- X#define DOS_TRUE (-1)
- X
- X#define NAMESIZE (256) /* Size of a buffer for storing names */
- X
- X#define BUFSTEP (128) /* Additional allocation during writes */
- X
- X#define FIRST_KEY (1)
- X
- X /* Flags to be stored in vb_flags */
- X#define ENVB_READ (0)
- X#define ENVB_WRITE (1)
- X
- X#define ENVF_READ (1<<ENVB_READ)
- X#define ENVF_WRITE (1<<ENVB_WRITE)
- X
- X#define MAX(x,y) ((x)>(y)?(x):(y))
- X
- X /* Forward References */
- Xextern char * mygetenv (register char *);
- Xextern char * getnextenv (register struct FileInfoBlock * fib,
- X register struct DosPacket * pkt);
- Xextern char * getenvname (register char *);
- Xextern void * ReAlloc (void *, long, long, long);
- X
- END_OF_FILE
- if test 2266 -ne `wc -c <'funcs.h'`; then
- echo shar: \"'funcs.h'\" unpacked with wrong size!
- fi
- # end of 'funcs.h'
- fi
- if test -f 'globals.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'globals.h'\"
- else
- echo shar: Extracting \"'globals.h'\" \(1136 characters\)
- sed "s/^X//" >'globals.h' <<'END_OF_FILE'
- X/*
- X * FILE
- X * globals.h
- X *
- X * DESCRIPTION
- X * This file conatins all the global defintions of the env-handler
- X * project. This file is read by env-handler.c (through env-handler.h)
- X * and funcs.c (through funcs.h)
- X */
- X
- X /* This is the only Global Variable. */
- Xextern struct ArpBase * ArpBase;
- X
- X
- X /* Global function references */
- Xextern void action_input (register struct DosPacket *,
- X struct MsgPort *);
- Xextern void action_read (register struct DosPacket *);
- Xextern void action_output (register struct DosPacket *,
- X struct MsgPort *);
- Xextern void action_write (register struct DosPacket *);
- Xextern void action_end (register struct DosPacket *);
- Xextern void action_lock (register struct DosPacket *,
- X struct MsgPort *,
- X struct DosList *);
- Xextern void action_copy_lock (register struct DosPacket *);
- Xextern void action_freelock (register struct DosPacket *);
- Xextern void action_delete (register struct DosPacket *);
- Xextern void action_examine_object (register struct DosPacket *);
- Xextern void action_examine_next (register struct DosPacket *);
- END_OF_FILE
- if test 1136 -ne `wc -c <'globals.h'`; then
- echo shar: \"'globals.h'\" unpacked with wrong size!
- fi
- # end of 'globals.h'
- fi
- if test -f 'makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makefile'\"
- else
- echo shar: Extracting \"'makefile'\" \(1046 characters\)
- sed "s/^X//" >'makefile' <<'END_OF_FILE'
- X#
- X# Makefile for the env-handler file.
- X# Written by Anders Lindgren
- X#
- X
- XCFLAGS = -v -b -cfsi # -d
- X
- XLNKFLG = BATCH VERBOSE NODEBUG
- XLIB =
- XMAP = MAP env.map HXSFL
- X
- X
- Xenv-handler : env-handler.o funcs.o
- X blink TO env-handler FROM env-handler.o funcs.o $(LIB) $(LNKFLG) $(MAP)
- X
- Xfuncs.o : funcs.c funcs.h
- X lc $(CFLAGS) funcs
- X
- Xenv-handler.o : env-handler.c env-handler.h
- X lc $(CFLAGS) env-handler
- X
- X
- Xtest : test.o
- X blink TO test FROM lib:arpc.o test.o LIB lib:arp.lib lib:lc.lib $(LNKFLG)
- X
- Xtest.o : test.c
- X lc test
- X
- X
- Xdie : die.o
- X blink TO die FROM lib:arpc.o die.o LIB lib:arp.lib lib:lc.lib $(LNKFLG)
- X
- Xdie.o : die.c
- X lc die
- X
- X#
- X# Backup all important files.
- X#
- X
- Xbackup :
- X lharc -a a backup3:env2manx.lzh env-handler env-handler.c env-handler.h funcs.c funcs.h globals.h env.doc die.c makefile mountlist test.c
- X
- X#
- X# Create the releasearchive.
- X#
- X
- Xrelease :
- X lharc -a u MyReleases:env2manx100.lzh env-handler env-handler.c env-handler.h funcs.c funcs.h globals.h env.doc makefile mountlist
- END_OF_FILE
- if test 1046 -ne `wc -c <'makefile'`; then
- echo shar: \"'makefile'\" unpacked with wrong size!
- fi
- # end of 'makefile'
- fi
- if test -f 'mountlist' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'mountlist'\"
- else
- echo shar: Extracting \"'mountlist'\" \(171 characters\)
- sed "s/^X//" >'mountlist' <<'END_OF_FILE'
- X/* Mountlist entry for the env: device. Merge it in the devs:mountlist */
- X
- XENV:
- X Handler = l:env-handler
- X stacksize = 4000
- X priority = 5
- X GlobVec = -1
- X#
- X
- END_OF_FILE
- if test 171 -ne `wc -c <'mountlist'`; then
- echo shar: \"'mountlist'\" unpacked with wrong size!
- fi
- # end of 'mountlist'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- --
- Submissions to comp.sources.amiga and comp.binaries.amiga should be sent to:
- amiga@cs.odu.edu
- or amiga@xanth.cs.odu.edu ( obsolescent mailers may need this address )
- or ...!uunet!xanth!amiga ( very obsolescent mailers need this address )
-
- Comments, questions, and suggestions s should be addressed to ``amiga-request''
- (only use ``amiga'' for submissions) at the above addresses.
-